//
//  LGSymptomViewController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/5/12.
//  症状

#import "LGSymptomViewController.h"
#import "LGSymptomViewCell.h"
#import "LGSymptomDetailView.h"
@interface LGSymptomViewController ()<UITableViewDataSource,UITableViewDelegate>
/**   */
@property (nonatomic , strong)UITableView *tableView;
/**   */
@property (nonatomic , strong)NSArray *dataArray;

@end

@implementation LGSymptomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];
    [self emptyViewWithSuperView:self.view frame:CGRectMake(0, viewPix(33), Screen_W, Screen_H)];
    self.emptyView.backgroundColor = [UIColor clearColor];
    [self requestData];
}

//模块被选中
-(void)viewWillAppearAction{
    [self requestData];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/patient.Physicalsign/symptomList" parameters:@{@"patient_id":self.patientid} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(code == 200){
            self.dataArray = returnData;
        }
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:@"暂无记录" offset:viewPix(50)];
        }
        [self.tableView reloadData];
    } error:^(NSError *error) {
        self.isfirst = NO;
        [self.emptyView stopBufferAction];
        if(self.dataArray.count == 0){
            [self.emptyView showViewWithImage:@"emptyView2" content:LGErrorMessage offset:viewPix(50)];
        }
    }];
}

-(void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LGSymptomViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dataDic = self.dataArray[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    LGSymptomDetailView *alertView = [[LGSymptomDetailView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
    alertView.dataDic = self.dataArray[indexPath.row];
    [[UIApplication sharedApplication].keyWindow addSubview:alertView];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return (self.dataArray.count>0)?viewPix(75):0.001;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if(self.dataArray.count>0){
        return [self tableHeadView];
    }else{
        return [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return (self.dataArray.count>0)?viewPix(15):0.001;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    if(self.dataArray.count>0){
        LGCornerFooterView *footView = [[LGCornerFooterView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(15))];
        footView.backgroundColor = [UIColor clearColor];
        footView.shadowView.cornerRidus = 7;
        footView.bottomMargin = viewPix(10);
        return footView;
    }else{
        return [[UIView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, 0.01)];
    }
}


-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.tableView.frame = CGRectMake(0, 0, Screen_W, self.view.bounds.size.height);
    self.emptyView.frame = CGRectMake(0, viewPix(33), Screen_W, self.view.bounds.size.height-viewPix(33));
}


-(UITableView *)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, self.view.bounds.size.height) style:UITableViewStyleGrouped];
        [_tableView registerClass:[LGSymptomViewCell class] forCellReuseIdentifier:@"cell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}

-(UIView *)tableHeadView{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, viewPix(75))];
    headView.backgroundColor = [UIColor clearColor];
    headView.clipsToBounds = YES;
    
    UILabel *titleLabel = [UILabel lableWithText:@"历史记录" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    titleLabel.frame = CGRectMake(viewPix(16), viewPix(13), viewPix(120), viewPix(22));
    [headView addSubview:titleLabel];
    
    UIView *shadowView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(45), Screen_W-viewPix(32), viewPix(50))];
    [shadowView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.1 radius:7];
    shadowView.backgroundColor = [UIColor whiteColor];
    [headView addSubview:shadowView];
    
    UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectMake(viewPix(72), 0, 0.5, viewPix(50))];
    lineView1.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    [shadowView addSubview:lineView1];
    
    UIView *lineView2 = [[UIView alloc]initWithFrame:CGRectMake(viewPix(182), 0, 0.5, viewPix(50))];
    lineView2.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    [shadowView addSubview:lineView2];
    
    UIView *lineView3 = [[UIView alloc]initWithFrame:CGRectMake(viewPix(293), 0, 0.5, viewPix(50))];
    lineView3.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    [shadowView addSubview:lineView3];
    
    UIView *lineView4 = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(36), Screen_W-viewPix(32), 0.5)];
    lineView4.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    [shadowView addSubview:lineView4];
    
    
    UILabel *symptomLabel = [UILabel lableWithText:@"症状" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    symptomLabel.frame = CGRectMake(0, 0, viewPix(72), viewPix(36));
    [shadowView addSubview:symptomLabel];
    
    UILabel *startLabel = [UILabel lableWithText:@"出现时间" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    startLabel.frame = CGRectMake(viewPix(72), 0, viewPix(110), viewPix(36));
    [shadowView addSubview:startLabel];
    
    UILabel *endLabel = [UILabel lableWithText:@"结束时间" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    endLabel.frame = CGRectMake(viewPix(182), 0, viewPix(110), viewPix(36));
    [shadowView addSubview:endLabel];
    
    UILabel *continueLabel = [UILabel lableWithText:@"持续" colorString:@"#666666" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
    continueLabel.frame = CGRectMake(viewPix(293), 0, viewPix(50), viewPix(36));
    [shadowView addSubview:continueLabel];
    
    
    return headView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
